<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <!-- <a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a> -->
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>
    </div>
</div>

<script>
    layui.use(['form', 'table', 'miniPage', 'lycms'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            miniPage = layui.miniPage,
            lycms = layui.lycms;
        table.render({
            elem: '#currentTableId',
            url: '/v1/admin/data/platelist',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                { field: 'title', title: '专题标题' },
                { field: 'alias', title: '专题别名' },
                { field: 'sign', title: '详情标识' },
                { field: 'collist', title: '采集列表', minWidth: 150 },
                { field: 'method', width: 120, title: '绑定方法', sort: true },
                {
  field: 'bindtype', width: 120, title: '功能类型', width: 100, align: "center", sort: true, templet: function (data) {
                        if (data.bindtype == 'search') {
                            return data.bindtype = "搜索";
                        } else {
                            return data.bindtype = "专题";
                        }
                    }
                },
                { field: 'sort', maxWidth: 50, title: '专题排序', width: 100, align: "center", sort: true },
                {
                    field: 'index', title: '展示首页', sort: true, width: 100, align: "center", templet: function (data) {
                        if (data.index == 'on') {
                            return data.index = "展示";
                        } else {
                            return data.index = "未展示";
                        }
                    }
                },
                {
                    field: 'close', title: '状态', width: 80, sort: true, align: "center", templet: function (data) {
                        if (data.close == 'on') {
                            return data.close = "启用";
                        } else {
                            return data.close = "未启用";
                        }
                    }
                },
                { title: '操作', width: 120, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],

        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var content = miniPage.getHrefContent('page/table/add.html');
                var openWH = miniPage.getOpenWidthHeight();

                var index = layer.open({
                    title: '编辑用户',
                    type: 1,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: [openWH[0] + 'px', openWH[1] + 'px'],
                    offset: [openWH[2] + 'px', openWH[3] + 'px'],
                    content: content,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                    console.log(data);

                    var info = {
                        bindtype: data.bindtype,
                        sign: data.sign,
                        alias: data.alias
                    }
                    //删除
                    $.post("/ask/action/system/plate/del", info, function (data, status) {
                        console.log(data.code);
                        if (data.code == "200") {
                            layer.msg(data.msg, { time: 1500 });
                        } else {
                            layer.msg(data.msg, { time: 1500 });
                        }
                    });
                });
            }
        });

        $(document).off('mousedown', '.layui-table-grid-down').
            on('mousedown', '.layui-table-grid-down', function (event) {
                table._tableTrCurrr = $(this).closest('td');
            });

        $(document).off('click', '.layui-table-tips-main [lay-event]').
            on('click', '.layui-table-tips-main [lay-event]', function (event) {
                var elem = $(this);
                var tableTrCurrr = table._tableTrCurrr;
                if (!tableTrCurrr) {
                    return;
                }
                var layerIndex = elem.closest('.layui-table-tips').attr('times');
                console.log(layerIndex);
                layer.close(layerIndex);
                table._tableTrCurrr.find('[lay-event="' + elem.attr('lay-event') + '"]').children("i").first().click();
            });

    });
</script>